home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
COM
/
NetCacheBack 0.9d6.sit
/
NetCacheBack 0.9d6 ƒ
/
NetCacheBack source
< prev
next >
Wrap
Text File
|
1996-05-12
|
12KB
|
394 lines
-- Netscapeェ Cache Back 0.9d6
-- Copyright ゥ 1995-96 Mizutori Tetsuya, May 12, 1996
-- global constants
set gCurrentFolder to "" as string
set gCacheRecordList to {} as list
-- global constants for NetCacheBack 0.9d6
set gTraceLog to true as boolean
set gVerbose to true as boolean
set gOverride to false as boolean
set gFormList to {} as list
set gTracingNow to 0 as number
set gTraceLogFile to "NetCacheBack log"
tell me to open {}
--
on open (docList)
local currItem
--
if docList is {} then set docList to {(choose file)}
--
--NetCacheBack 0.9d6
tell me to initGlobals()
tell me to getPreferences()
--
tell me to setupConstants by the first item of docList
--
repeat with currItem in docList
tell me to moveCacheFile against currItem
end repeat
end open
--NetCacheBack 0.9d6
to initGlobals()
global gCurrentFolder, gCacheRecordList
global gTraceLog, gVerbose, gOverride
global gFormList
global gTracingNow, gTraceLogFile
--
set gCurrentFolder to ""
set gCacheRecordList to {}
--
set gTraceLog to true
set gVerbose to true
set gOverride to false
set gFormList to {}
set gTracingNow to 0
set gTraceLogFile to "NetCacheBack log"
--
end initGlobals
to setupConstants by currentFile
global gCurrentFolder, gCacheRecordList, gTraceLogFile
local refFile, cacheRecordList, cachelog, ccacheLog, viewBy
--
tell application "Finder" to get the container of currentFile
copy the result to gCurrentFolder
--
--NetCacheBack 0.9d6
copy ((gCurrentFolder as string) & gTraceLogFile) to gTraceLogFile
--
copy ((gCurrentFolder as string) & "Cache log") to cachelog
copy ((gCurrentFolder as string) & "CCache log") to ccacheLog
--
tell application "Finder"
open the gCurrentFolder
set viewBy to the view of the gCurrentFolder
if exists the (alias cachelog) then
if exists the (alias ccacheLog) then
if the modification date of the (alias ccacheLog) comes after ツ
the modification date of the (alias cachelog) then
tell application "NetCacheResolver"
open {(alias ccacheLog)}
quit
end tell
end if
end if
try
set refFile to open for access (alias cachelog)
set cacheRecordList to read refFile as list using delimiters return
close access refFile
--
tell application "NetCacheResolver"
if the viewBy is byDate then
sort cacheRecordList by date
else if the viewBy is bySize then
sort cacheRecordList by size
else
sort cacheRecordList by name
end if
copy the result to gCacheRecordList
quit
end tell
on error
tell me to errorMessage for "Canユt read メCache logモ file"
end try
else if exists the (alias ccacheLog) then
tell application "NetCacheResolver"
if the viewBy is byDate then
resolve {(alias ccacheLog)} with sorted by date
else if the viewBy is bySize then
resolve {(alias ccacheLog)} with sorted by size
else
resolve {(alias ccacheLog)} with sorted by name
end if
copy the result to gCacheRecordList
quit
end tell
else
tell me to errorMessage for "Canユt find メCache logモ or メCCache logモ file"
end if
end tell
end setupConstants
to moveCacheFile against cacheFile
global gCurrentFolder, gCacheRecordList
local refFile
local cacheRecord, cachefolder, cacheName
local url, urlFolder, urlName
local n
--
tell application "Finder"
copy the container of cacheFile to cachefolder
copy the name of cacheFile to cacheName
end tell
--
set n to 1
repeat with cacheRecord in gCacheRecordList
if cacheName is in the cacheRecord then
tell me to renameCacheFile(cachefolder, cacheName, cacheRecord)
set the item n of gCacheRecordList to ""
exit repeat
end if
set n to n + 1
end repeat
--
end moveCacheFile
to renameCacheFile(cachefolder, cacheName, cacheRecord)
global gCurrentFolder, gCacheRecordList
global gTraceLog, gVerbose, gOverride
local oldDelimiters, cacheItems, cacheFilePath
local url, urlFolder, urlName, urlItems
local targetFolderPath, fileType
--
copy the text item delimiters to oldDelimiters
--
tell me to set the text item delimiters to {tab}
copy every text item in cacheRecord to cacheItems
copy the 6th item of cacheItems to fileType
copy the 5th item of cacheItems to url
--
tell me to set the text item delimiters to {"/"}
copy every text item in url to urlItems
copy (items 3 through -2 in urlItems) to urlFolder
copy the last item in urlItems to urlName
tell me to set the text item delimiters to {""}
if urlName is "" then set the urlName to "index.html"
if urlName contains "#" then ツ
copy characters 1 thru ((offset of "#" in urlName) - 1) in urlName as string to urlName
--
tell me to set the text item delimiters to {":"}
copy ((cachefolder as string) & cacheName) to cacheFilePath
copy ((gCurrentFolder as string) & (urlFolder as string)) to targetFolderPath
--
tell me to attachFolder at targetFolderPath as string
tell me to setFileAttribute of (alias cacheFilePath) by fileType
--
copy oldDelimiters to the text item delimiters
--
tell application "Finder"
try
move alias cacheFilePath to the folder targetFolderPath
--NetCacheBack 0.9d6
if not gOverride then
tell me to generateFileName by urlName
copy the result to urlName
end if
if the file urlName in the folder targetFolderPath exists then
if not gOverride then
--NetCacheBack 0.9d6
tell me to traceLog for "メ" & targetFolderPath & ":" & urlName & "モ was replaced."
delete the file urlName in the folder targetFolderPath
else
error
end if
end if
set the name of file cacheName in the folder targetFolderPath to urlName
on error
--NetCacheBack 0.9d6
tell me to traceLog for "Canユt move メ" & cacheName & "モ to " & targetFolderPath & ":" & urlName
--NetCacheBack 0.9d6
if gVerbose then ツ
display dialog "Canユt move メ" & cacheName & "モ to " & targetFolderPath & ":" & urlName ツ
buttons {"OK"} default button 1 with icon caution
end try
end tell
end renameCacheFile
to attachFolder at pathName -- as string
local listFolders, numbFolders, parentFolder, targetFolder
--
tell application "Finder"
if pathName is "" then
return path to desktop -- case of the Desktop
else if the folder pathName exists then
return the folder pathName -- case of the Folder
else if the disk pathName exists then
return the disk pathName -- case of the Volume
else
--beep
tell me to set the text item delimiters to {":"}
copy every text item of pathName to the listFolders
copy (the count of items in the listFolders) to the numbFolders
if listFolders ends with {""} then ツ
copy the numbFolders - 1 to the numbFolders
copy the item numbFolders in the listFolders to targetFolder
copy (every item in (items 1 thru (numbFolders - 1) in the listFolders)) & {""} ツ
to parentFolder
tell me to attachFolder at the parentFolder as string
make new folder at the result with properties {name:targetFolder}
return the result
end if
end tell
end attachFolder
-- NetCacheBack 0.9d6
to generateFileName by theFilename
local thePos, changed, theFilename0
local oldDelimiters
--
copy the text item delimiters to oldDelimiters
tell me to set the text item delimiters to {""}
--
copy theFilename to theFilename0
set changed to false
--
-- truncate file length in 31 characters
set thePos to (count of theFilename)
if thePos is greater than 31 then
copy ツ
(characters 1 thru 25 in theFilename as string) & ツ
(characters (thePos-5) thru (thePos) in theFilename as string) ツ
to theFilename
set changed to true
end if
--
-- zap ":" in filename
repeat
set thePos to offset of ":" in theFilename
if thePos is 0 then exit repeat
copy ツ
(characters 1 thru (thePos - 1) in theFilename as string) & "_" & ツ
(characters (thePos + 1) thru (count of theFilename) in theFilename as string) ツ
to theFilename
set changed to true
end repeat
--
if changed then ツ
tell me to traceLog for "メ" & theFilename0 & "モ was truncated or zapped to メ" & theFilename & "モ."
--
copy oldDelimiters to the text item delimiters
--
return theFilename as string
end generateFileName
-- NetCacheBack 0.9d5
--to setFileAttribute of fileRef by fileType
-- tell application "Finder"
-- if fileType contains "text/html" then
-- set the file type of fileRef to "TEXT"
-- set the creator type of fileRef to "MOSS"
-- else if fileType contains "text/plain" then
-- set the file type of fileRef to "TEXT"
-- set the creator type of fileRef to "ttxt"
-- else if fileType contains "image/gif" then
-- set the file type of fileRef to "GIFf"
-- set the creator type of fileRef to "JVWR"
-- else if fileType contains "image/jpeg" then
-- set the file type of fileRef to "JPEG"
-- set the creator type of fileRef to "JVWR"
-- end if
-- end tell
--end setFileAttribute
-- NetCacheBack 0.9d6
-- The file types are read from "NetCacheBack Pref" file.
to setFileAttribute of fileRef by fileType
global gTraceLog, gVerbose, gOverride, gFormList
local theFormPair
--
tell application "Finder"
repeat with theFormPair in gFormList
if the theFormPair begins with fileType then
set the file type of fileRef to the 2nd item of theFormPair
set the creator type of fileRef to the 3rd item of theFormPair
exit repeat
end if
end repeat
end tell
end setFileAttribute
-- NetCacheBack 0.9d6
to getPreferences()
global gTraceLog, gVerbose, gOverride, gFormList
local prefName, prefFile, prefList, theItem
--
-- read preference data from pref file
set prefName to ((path to preferences folder) as string) & "NetCacheBack Prefs"
set prefFile to open for access (file prefName)
set prefList to read prefFile as list using delimiters return
close access prefFile
--
-- set variable status due to preference data
ignoring case and white space
repeat with theItem in prefList
if theItem starts with ";" then
-- the line begins with ";" is a comment
else if theItem starts with "tracelog=" then
set gTraceLog to ("=yes" is in theItem) as boolean
else if theItem starts with "verbose=" then
set gVerbose to ("=yes" is in theItem) as boolean
else if theItem starts with "override=" then
set gOverride to ("=yes" is in theItem) as boolean
else if theItem starts with "form=" then
tell me to getFormPair from theItem
copy (gFormList & the result) as list to gFormList
end if
end repeat
end ignoring
end getPreferences
-- NetCacheBack 0.9d6
to getFormPair from theString
local thePair, thePairList, oldDelimiters
--
copy the text item delimiters to oldDelimiters
--
tell me to set the text item delimiters to {""}
copy characters ((offset of "=" in theString) + 1) thru (count of theString) in theString as string ツ
to thePair
if thePair ends with "¥"" then
copy characters ((offset of "¥"" in thePair) + 1) thru ((count of thePair) - 1) in thePair as string ツ
to thePair
end if
--
tell me to set the text item delimiters to {tab}
copy every text item in thePair to thePairList
--
copy oldDelimiters to the text item delimiters
--
return {thePairList} as list
end getFormPair
-- NetCacheBack 0.9d6
on traceLog for errMessage
global gTraceLog, gTracingNow, gTraceLogFile
local refFile
--
if not gTraceLog then return
set gTracingNow to (gTracingNow + 1)
--
try
set refFile to (open for access file gTraceLogFile with write permission)
if gTracingNow is equal to 1 then
set eof refFile to 0
write "### NetCacheBack Log on " & (current date) & return to refFile
end if
write "[" & (gTracingNow as string) & "] " & errMessage & return ツ
to refFile starting at eof
close access refFile
--
on error
-- do nothing
end try
end traceLog
on errorMessage for errMessage
error errMessage
end errorMessage